using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class ProductPrice
    {
         #region Common
        public eProductPrice Data;

        public ProductPrice()
        {
            Data = new eProductPrice();
		}

        ~ProductPrice()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cProductPrice objDAL = new cProductPrice();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cProductPrice objDAL = new cProductPrice();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int UpdateStatus(int ID, int Status)
        {
            int nResult = 0;
            cProductPrice objDAL = new cProductPrice();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.Status = Status;

                objDAL.Save();
                nResult = objDAL.ProductID ;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public int Insert()
        {
            int nResult = 0;
            cProductPrice objInfor = new cProductPrice(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.PriceID ;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cProductPrice objInfor = new cProductPrice();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

     

        private void MappingData(cProductPrice objInfor)
        {
            objInfor.ProductID = Data.ProductID;
            objInfor.Price = Data.Price;
            objInfor.DateEffect = Data.DateEffect; 
            objInfor.Status = Data.Status;
        }

        private void ConvertData(cProductPrice objInfor)
        {
            Data.ProductID = objInfor.ProductID;
            Data.Price = objInfor.Price;
            Data.DateEffect = objInfor.DateEffect;
            Data.Status = objInfor.Status;
        }

        public DataTable Search(int DateEffect, int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cProductPrice objDAL = new cProductPrice();
            tbResult = objDAL.Search(DateEffect, PageIndex, PageSize, ref  PageCount);
            return tbResult;
        }

         public DataTable DeleteByDateEffect(int DateEffect)
        {
            DataTable tbResult = new DataTable();
            cProductPrice objDAL = new cProductPrice();
            tbResult = objDAL.DeleteByDateEffect(DateEffect);
            return tbResult;
        }
         public DataTable GetForChart()
         {
             DataTable tbResult = new DataTable();
             cProductPrice objDAL = new cProductPrice();
             tbResult = objDAL.GetForChart();
             return tbResult;
         }
    
        #endregion
    }
}
